home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbpixmap.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  7.1 KB  |  289 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.16;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbpixmap.c,v 5.5 89/07/28 11:59:59 rws Exp $ */
  50.  
  51. /* pixmap management
  52.    written by drewry, september 1986
  53.  
  54.    on a monchrome device, a pixmap is a bitmap.
  55. */
  56.  
  57. #include "Xmd.h"
  58. #include "pixmapstr.h"
  59. #include "maskbits.h"
  60.  
  61. #include "mfb.h"
  62. #include "mi.h"
  63.  
  64. #include "servermd.h"
  65.  
  66. PixmapPtr
  67. mfbCreatePixmap (pScreen, width, height, depth)
  68.     ScreenPtr    pScreen;
  69.     int        width;
  70.     int        height;
  71.     int        depth;
  72. {
  73.     register PixmapPtr pPixmap;
  74.     int size;
  75.  
  76.     if (depth != 1)
  77.     return NullPixmap;
  78.  
  79.     size = PixmapBytePad(width, 1);
  80.     pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + (height * size));
  81.     if (!pPixmap)
  82.     return NullPixmap;
  83.     pPixmap->drawable.type = DRAWABLE_PIXMAP;
  84.     pPixmap->drawable.class = 0;
  85.     pPixmap->drawable.pScreen = pScreen;
  86.     pPixmap->drawable.depth = 1;
  87.     pPixmap->drawable.bitsPerPixel = 1;
  88.     pPixmap->drawable.id = 0;
  89.     pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  90.     pPixmap->drawable.x = 0;
  91.     pPixmap->drawable.y = 0;
  92.     pPixmap->drawable.width = width;
  93.     pPixmap->drawable.height = height;
  94.     pPixmap->devKind = size;
  95.     pPixmap->refcnt = 1;
  96.     pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
  97.     return pPixmap;
  98. }
  99.  
  100. Bool
  101. mfbDestroyPixmap(pPixmap)
  102.     PixmapPtr pPixmap;
  103. {
  104.     if(--pPixmap->refcnt)
  105.     return TRUE;
  106.     xfree(pPixmap);
  107.     return TRUE;
  108. }
  109.  
  110.  
  111. PixmapPtr
  112. mfbCopyPixmap(pSrc)
  113.     register PixmapPtr    pSrc;
  114. {
  115.     register PixmapPtr    pDst;
  116.     int        size;
  117.  
  118.     size = pSrc->drawable.height * pSrc->devKind;
  119.     pDst = (PixmapPtr)xalloc(sizeof(PixmapRec) + size);
  120.     if (!pDst)
  121.     return NullPixmap;
  122.     pDst->drawable = pSrc->drawable;
  123.     pDst->drawable.id = 0;
  124.     pDst->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  125.     pDst->devKind = pSrc->devKind;
  126.     pDst->refcnt = 1;
  127.     pDst->devPrivate.ptr = (pointer)(pDst + 1);
  128.     bcopy((char *)pSrc->devPrivate.ptr, (char *)pDst->devPrivate.ptr, size);
  129.     return pDst;
  130. }
  131.  
  132.  
  133. /* replicates a pattern to be a full 32 bits wide.
  134.    relies on the fact that each scnaline is longword padded.
  135.    doesn't do anything if pixmap is not a factor of 32 wide.
  136.    changes width field of pixmap if successful, so that the fast
  137.     XRotatePixmap code gets used if we rotate the pixmap later.
  138.  
  139.    calculate number of times to repeat
  140.    for each scanline of pattern
  141.       zero out area to be filled with replicate
  142.       left shift and or in original as many times as needed
  143. */
  144. void
  145. mfbPadPixmap(pPixmap)
  146.     PixmapPtr pPixmap;
  147. {
  148.     register int width = pPixmap->drawable.width;
  149.     register int h;
  150.     register int mask;
  151.     register unsigned int *p;
  152.     register unsigned int bits;    /* real pattern bits */
  153.     register int i;
  154.     int rep;            /* repeat count for pattern */
  155.  
  156.     if (width >= 32)
  157.     return;
  158.  
  159.     rep = 32/width;
  160.     if (rep*width != 32)
  161.     return;
  162.  
  163.     mask = endtab[width];
  164.  
  165.     p = (unsigned int *)(pPixmap->devPrivate.ptr);
  166.     for (h=0; h < pPixmap->drawable.height; h++)
  167.     {
  168.     *p &= mask;
  169.     bits = *p;
  170.     for(i=1; i<rep; i++)
  171.     {
  172.         bits = SCRRIGHT(bits, width);
  173.         *p |= bits;
  174.     }
  175.     p++;
  176.     }
  177.     pPixmap->drawable.width = 32;
  178. }
  179.  
  180. /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
  181.  * words are 32 bits wide, and that the least significant bit appears on the
  182.  * left.
  183.  */
  184. void
  185. mfbXRotatePixmap(pPix, rw)
  186.     PixmapPtr    pPix;
  187.     register int rw;
  188. {
  189.     register long    *pw, *pwFinal;
  190.     register unsigned long    t;
  191.  
  192.     if (pPix == NullPixmap)
  193.         return;
  194.  
  195.     pw = (long *)pPix->devPrivate.ptr;
  196.     rw %= (int)pPix->drawable.width;
  197.     if (rw < 0)
  198.     rw += (int)pPix->drawable.width;
  199.     if(pPix->drawable.width == 32)
  200.     {
  201.         pwFinal = pw + pPix->drawable.height;
  202.     while(pw < pwFinal)
  203.     {
  204.         t = *pw;
  205.         *pw++ = SCRRIGHT(t, rw) | 
  206.             (SCRLEFT(t, (32-rw)) & endtab[rw]);
  207.     }
  208.     }
  209.     else
  210.     {
  211.     /* We no longer do this.  Validate doesn't try to rotate odd-size
  212.      * tiles or stipples.  mfbUnnatural<tile/stipple>FS works directly off
  213.      * the unrotate tile/stipple in the GC
  214.      */
  215.         ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
  216.     }
  217.  
  218. }
  219.  
  220. /* Rotates pixmap pPix by h lines.  Assumes that h is always less than
  221.    pPix->height
  222.    works on any width.
  223.  */
  224. void
  225. mfbYRotatePixmap(pPix, rh)
  226.     register PixmapPtr    pPix;
  227.     int    rh;
  228. {
  229.     int nbyDown;    /* bytes to move down to row 0; also offset of
  230.                row rh */
  231.     int nbyUp;        /* bytes to move up to line rh; also
  232.                offset of first line moved down to 0 */
  233.     char *pbase;
  234.     char *ptmp;
  235.     int    height;
  236.  
  237.     if (pPix == NullPixmap)
  238.     return;
  239.     height = (int) pPix->drawable.height;
  240.     rh %= height;
  241.     if (rh < 0)
  242.     rh += height;
  243.  
  244.     pbase = (char *)pPix->devPrivate.ptr;
  245.  
  246.     nbyDown = rh * pPix->devKind;
  247.     nbyUp = (pPix->devKind * height) - nbyDown;
  248.     if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
  249.     return;
  250.  
  251.     bcopy(pbase, ptmp, nbyUp);        /* save the low rows */
  252.     bcopy(pbase+nbyUp, pbase, nbyDown);    /* slide the top rows down */
  253.     bcopy(ptmp, pbase+nbyDown, nbyUp);    /* move lower rows up to row rh */
  254.     DEALLOCATE_LOCAL(ptmp);
  255. }
  256.  
  257. void
  258. mfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
  259.     register PixmapPtr psrcPix, *ppdstPix;
  260.     int    xrot, yrot;
  261. {
  262.     register PixmapPtr pdstPix;
  263.  
  264.     if ((pdstPix = *ppdstPix) &&
  265.     (pdstPix->devKind == psrcPix->devKind) &&
  266.     (pdstPix->drawable.height == psrcPix->drawable.height))
  267.     {
  268.     bcopy((char *)psrcPix->devPrivate.ptr,
  269.           (char *)pdstPix->devPrivate.ptr,
  270.           psrcPix->drawable.height * psrcPix->devKind);
  271.     pdstPix->drawable.width = psrcPix->drawable.width;
  272.     pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  273.     }
  274.     else
  275.     {
  276.     if (pdstPix)
  277.         mfbDestroyPixmap(pdstPix);
  278.     *ppdstPix = pdstPix = mfbCopyPixmap(psrcPix);
  279.     if (!pdstPix)
  280.         return;
  281.     }
  282.     mfbPadPixmap(pdstPix);
  283.     if (xrot)
  284.     mfbXRotatePixmap(pdstPix, xrot);
  285.     if (yrot)
  286.     mfbYRotatePixmap(pdstPix, yrot);
  287. }
  288. @
  289.